import "@site/src/languages/highlight";

# Unit Class

**Description:**

&emsp;&emsp;A class for creating instances of Unit.

## GroundSensorTag

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The tag for the "GroundSensor" attached to each "Unit".

**Signature:**
```tl
const GroundSensorTag: integer
```

## DetectSensorTag

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The tag for the "DetectSensor" attached to each "Unit".

**Signature:**
```tl
const DetectSensorTag: integer
```

## AttackSensorTag

**Type:** Readonly Field.

**Description:**

&emsp;&emsp;The tag for the "AttackSensor" attached to each "Unit".

**Signature:**
```tl
const AttackSensorTag: integer
```

## __call

**Type:** Metamethod.

**Description:**

&emsp;&emsp;A metamethod that creates a new "Unit" object.

**Signature:**
```tl
metamethod __call: function(
		self: UnitClass,
		unitDef: Dictionary,
		physicsWorld: PhysicsWorld,
		entity: Entity,
		pos: Vec2,
		rot?: number --[[0.0]]
	): Unit
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| unitDef | Dictionary | A "Dictionary" object that defines the properties and behavior of the "Unit". |
| physicsWorld | PhysicsWorld | A "PhysicsWorld" object that represents the physics simulation world. |
| entity | Entity | An "Entity" object that represents the "Unit" in ECS system. |
| pos | Vec2 | A "Vec2" object that specifies the initial position of the "Unit". |
| rot | number | [optional] An optional number that specifies the initial rotation of the "Unit" (default is 0.0). |

**Returns:**

| Return Type | Description |
| --- | --- |
| Unit | The newly created "Unit" object. |

## __call

**Type:** Metamethod.

**Description:**

&emsp;&emsp;A metamethod that creates a new "Unit" object.

**Signature:**
```tl
metamethod __call: function(
		self: UnitClass,
		unitDefName: string,
		physicsWorldName: string,
		entity: Entity,
		pos: Vec2,
		rot?: number --[[0.0]]
	): Unit
```

**Parameters:**

| Parameter | Type | Description |
| --- | --- | --- |
| unitDefName | string | A string that specifies the name of the "Unit" definition to retrieve from Data.store table. |
| physicsWorldName | string | A string that specifies the name of the "PhysicsWorld" object to retrieve from Data.store table. |
| entity | Entity | An "Entity" object that represents the "Unit" in ECS system. |
| pos | Vec2 | A "Vec2" object that specifies the initial position of the "Unit". |
| rot | number | [optional] An optional number that specifies the initial rotation of the "Unit" (default is 0.0). |

**Returns:**

| Return Type | Description |
| --- | --- |
| Unit | The newly created "Unit" object. |